<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="author" content="JZH">
    <title>原型链继承练习</title>
</head>
<body>
        
</body>
<html>
<script>
//创建People构造函数 
    function People(name,age,isMale){
        this.name = name;
        this.age = age;
        this.isMale = isMale;
    }
   People.prototype.say = function(word){
     console.log(this.name+word);
   }

   var people = new People('Lucy','22',false);
   console.dir(people); 
   console.log('今天星期一');

//创建Boy构造函数 
function Boy(name,age,isMale){
People.call(this,name,age,isMale);
}

//继承公共域
function Child(){};
Child.prototype = People.prototype;
var obj = new Child();
Boy.prototype = obj;


//扩展属性 
Boy.prototype.play = function(game,hours){
    console.log(this.name+'玩'+game+hours+'小时');
}
var boy = new Boy('Tom',25,true);
console.dir(boy);
console.log('Tom','说hello!');
boy.play('消消乐','2');

//创建Girl构造函数 
function Girl(name,age,isMale){
 People.call(this,name,age,isMale);   
}

//继承公共域 
function Baby(){};
Baby.prototype = People.prototype;
var obj = new Baby();
Girl.prototype = obj;

//扩展属性 
Girl.prototype.isLongHair = '是长发';
Girl.prototype.goShopping = function(place,hours){
    console.log(this.name+'去'+place+'逛街'+hours+'小时');
}
//输出对象 
var girl = new Girl('Lily','23',false);
console.dir(girl);
console.log('Lily','说hello!')
girl.goShopping('二七广场','3');
</script>